﻿<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>用户-修改</title>

    <link rel="shortcut icon" href="favicon.ico">
	<link href="css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
	<link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="css/animate.min.css" rel="stylesheet">
    <link href="css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <link href="css/style.min.css?v=4.0.0" rel="stylesheet">
	<style>
		.control-label{
			line-height:35px;
			text-align:center;
		}

		.ibox-content{
			padding:0 0 20px 0;
		}
	</style>
</head>

<body class="gray-bg">
    <div class="wrapper animated fadeInRight">

        <div class="row">
			<div class="ibox-content">
				<form id="argForm" class="form-horizontal m-t">
					<div class="form-group">
						<label class="col-xs-3 control-label">用户昵称：</label>
						<div class="col-xs-8">
							<input disabled id="nickName" class="form-control" type="text">
							<!--<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 这里写点提示的内容</span>-->
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-3 control-label">用户名：</label>
						<div class="col-xs-8">
							<input name="username" type="hidden" class="form-control" type="text">
							<input disabled id="username" class="form-control" type="text">
							<!--<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 这里写点提示的内容</span>-->
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-3 control-label">状态：</label>
						<div class="col-xs-8">
							<div class="radio i-checks">
								<label>
									<input id="status_on" type="radio" checked="" value="ON" name="status"> <i></i>启用</label>

								<label>
									<input id="status_off" type="radio" value="OFF" name="status"> <i></i>禁用</label>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-3 control-label">所属角色：</label>
						<div class="col-xs-8">
							<select id="roleCode" class="form-control" name="roleCode">
							</select>
						</div>
					</div>
					<div class="form-group">
						<div class="col-xs-3 col-xs-offset-8">
							<button class="btn btn-primary" onclick="updateUserRoleStatus();" type="button">提交</button>
						</div>
					</div>
				</form>
			</div>
        </div>
    </div>
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.5"></script>
    <script src="js/content.min.js?v=1.0.0"></script>
	<script src="js/plugins/toastr/toastr.min.js"></script>
    <script src="js/plugins/validate/jquery.validate.min.js"></script>
    <script src="js/plugins/validate/messages_zh.min.js"></script>
    <script src="js/plugins/iCheck/icheck.min.js"></script>
	<script src="js/custom/layTool.js"></script>
    <script type="text/javascript" src="js/custom/app.js" charset="UTF-8"></script>
    <script type="text/javascript" src="js/custom/tools.js" charset="UTF-8"></script>
	<script>
        $(document).ready(function(){$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})});
    </script>

	<script>
		$(function(){

			//初始化角色code和用户信息（全局）
			username = getQueryString("username");
			getAllSysRoleCodeAndName();

			var url = 'sysUser/getSysUserAndRoleByUsername';
			jQuery.ajax({
				url:domain + url,
				type:"get",
				data:{"username":username},
				crossDomain:true,
				xhrFields:{
					withCredentials:true
				},
				success:function (data) {
					if(data.status == 200){

						//拼凑html
						combHTML(data.data);
					}else{
						top.toastr.warning(data.msg);
					}
				},
				error:function(data) {
					top.toastr.error("查询列表失败，请检查网络");
				}
			})
		})

		function combHTML(data){
			$("input[name=username]").val(data.username);
			$("#username").val(data.username);
			$("#nickName").val(data.nickName);
			$("#roleCode").val(data.roleCode);
			var status = data.status;
			if (status == "ON"){
				$("#status_on").iCheck('check');
			}else{
				$("#status_off").iCheck('check');
			}
			$("#note").val(data.note);
		}

		function getAllSysRoleCodeAndName(){
			var url = 'sysRole/getAllSysRoleCodeAndNameByStatus';

			jQuery.ajax({
				url:domain + url,
				type:"get",
				data:{"status":""},
				contentType:"application/json;charset=utf-8",
				crossDomain:true,
				async: false,
				xhrFields:{
					withCredentials:true
				},
				success:function (data) {
					if(data.status == 200){
						 combRoleCodeAndName(data.data);
					}else{
						top.toastr.warning(data.msg);
					}
				},
				error:function(data) {
					top.toastr.error("操作失败，请检查网络");
				}
			})
		}

		function combRoleCodeAndName(data){
			var htmls = new Array();
			for (var i=0;i<data.length;i++){
				htmls.push('<option value="'+ data[i].roleCode +'">'+ data[i].roleName +'</option>');

			}
			$("#roleCode").html(htmls.join(''));
		}

		//切换角色或状态
		function updateUserRoleStatus(){
			var url = 'sysUser/updateSysUserRoleStatus';
			var formData = new FormData($("form#argForm")[0]);

			jQuery.ajax({
				url:domain + url,
				type:"post",
				data:formData2JsonStr(formData),
				//contentType:"application/json;charset=utf-8",
				crossDomain:true,
				xhrFields:{
					withCredentials:true
				},
				success:function (data) {
					if(data.status == 200){
						var arr = [1,10,""];
						callFn("searchSysUser",arr);
					}else{
						top.toastr.warning(data.msg);
					}
				},
				error:function(data) {
					top.toastr.error("操作失败，请检查网络");
				}
			})
		}

	</script>

</body>

</html>
